package com.yerbamateprimer.model;

import java.io.Serializable;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.google.common.base.Preconditions;

/**
 * This class models a yerba mate,
 * as the cup, the yerba and the 
 * straw, ready to drink it.
 * 
 * @author Matias Liwski
 * @version 1.0
 */
public class Mate implements Serializable{
	private static final long serialVersionUID = -6862321098530308920L;
	private Long id;
	private String yerbaBrand;
	private Sweetness sweetener;
	private Long buildingTime;
	private Long restingTime;
	private Long primingTime;
	private Long drinkingTime;

	/**
	 * @param id The id of the Mate.
	 * @param yerbaBrand The yerba brand of the Mate.
	 * @param sweetener The sweetener of the Mate.
	 * @param buildingTime The building time of the Mate, in milliseconds.
	 * @param restingTime The resting time of the Mate, in milliseconds.
	 * @param primingTime The priming time of the Mate, in milliseconds.
	 * @param drinkingTime The drinking time of the Mate, in milliseconds.
	 */
	public Mate(Long id, String yerbaBrand, Sweetness sweetener,
			Long buildingTime, Long restingTime, Long primingTime,
			Long drinkingTime) {
		setId(id);
		setYerbaBrand(yerbaBrand);
		setSweetner(sweetener);
		setBuildingTime(buildingTime);
		setRestingTime(restingTime);
		setPrimingTime(primingTime);
		setDrinkingTime(drinkingTime);
	}

	/**
	 * @return The id of the Mate.
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id The id of the Mate, to set.
	 */
	public void setId(Long id) {
		Preconditions.checkArgument(id != null && id > 0, "The id has to be greather than zero (id=" + id + ").");
		this.id = id;
	}

	/**
	 * @return The yerba brand of the Mate.
	 */
	public String getYerbaBrand() {
		return yerbaBrand;
	}

	/**
	 * @param yerbaBrand The yerba brand of the Mate, to set.
	 */
	public void setYerbaBrand(String yerbaBrand) {
		Preconditions.checkArgument(yerbaBrand != null && !yerbaBrand.equals(""), "The yerba brand couldn't be null or empty (yerbaBrand=" + yerbaBrand + ").");
		this.yerbaBrand = yerbaBrand;
	}

	/**
	 * @return The sweetener of the Mate.
	 */
	public Sweetness getSweetner() {
		return sweetener;
	}

	/**
	 * @param sweetener The sweetener of the Mate, to set.
	 */
	public void setSweetner(Sweetness sweetener) {
		Preconditions.checkArgument(sweetener != null, "The sweetener couldn't be null (sweetener=" + sweetener + ").");
		this.sweetener = sweetener;
	}
	/**
	 * @return The building time of the Mate, in milliseconds.
	 */
	public Long getBuildingTime() {
		return buildingTime;
	}
	/**
	 * @param buildingTime The building time of the Mate, in milliseconds, to set.
	 */
	public void setBuildingTime(Long buildingTime) {
		Preconditions.checkArgument(buildingTime != null && buildingTime > 0, "The building time has to be greather than zero (buildingTime=" + buildingTime + ").");
		this.buildingTime = buildingTime;
	}
	/**
	 * @return The resting time of the Mate, in milliseconds.
	 */
	public Long getRestingTime() {
		return restingTime;
	}
	/**
	 * @param restingTime The resting time of the Mate, in milliseconds, to set.
	 */
	public void setRestingTime(Long restingTime) {
		Preconditions.checkArgument(restingTime != null && restingTime > 0, "The resting time has to be greather than zero (restingTime=" + restingTime + ").");
		this.restingTime = restingTime;
	}
	/**
	 * @return The priming time of the Mate, in milliseconds.
	 */
	public Long getPrimingTime() {
		return primingTime;
	}
	/**
	 * @param primingTime The priming time of the Mate, in milliseconds, to set.
	 */
	public void setPrimingTime(Long primingTime) {
		Preconditions.checkArgument(primingTime != null && primingTime > 0, "The priming time has to be greather than zero (primingTime=" + primingTime + ").");
		this.primingTime = primingTime;
	}
	/**
	 * @return The drinking time of the Mate, in milliseconds.
	 */
	public Long getDrinkingTime() {
		return drinkingTime;
	}
	/**
	 * @param drinkingTime The drinking time of the Mate, in milliseconds, to set.
	 */
	public void setDrinkingTime(Long drinkingTime) {
		Preconditions.checkArgument(drinkingTime != null && drinkingTime > 0, "The drinking time has to be greather than zero (drinkingTime=" + drinkingTime + ").");
		this.drinkingTime = drinkingTime;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE, false, false);
	}
}